
//账号验证登录
$(function () {
	$("footer").load("./footer.html")
	var tmpArr=[]
	var userObj=JSON.parse(CookieTools.getCookieByName("usermessage")||'{}');
	if(userObj.uname){
		$("[name='uphone2']").val(userObj.uname)
		$("[name='upwd2']").val(userObj.upwd)
	}

	$.idcode.setCode()
	$(".loadbyname").on("submit",function () {
		var unamestr=$("[name='uphone2']").val()
		var upwdstr=$("[name='upwd2']").val()
		if(unamestr==""){
			layer.msg("请输入用户名哦")
			return false
		}
		if(upwdstr==""){
			layer.msg("请输入密码哦")
			return false
		}
		var IsBy = $.idcode.validateCode()
		if (!IsBy) {
			layer.msg("验证码有误哟")
			return  false;
		}
		let data={
			"uphone2": $("[name='uphone2']").val(),
			"upwd": $("[name='upwd2']").val()
		}
		$.ajax({
			url:"./../server/loaginServer.php",
			data:data,
			dataType:"json",
			type:"post"
		}).then(function (res) {
			console.log(res)
			localStorage.setItem("user",JSON.stringify(res.data));
			var selector=$("[name='remeber']").prop("checked")
			if(res.status!=1){
				layer.msg("用户名或密码有误哟")
				return false
			}
			if(res.status==1){
				if(selector){
					var objUser={}
					console.log(res.data)
					objUser.uname=res.data.utelphone
					objUser.upwd=res.data.upwd
					console.log(objUser)
					tmpArr.push(objUser)

					CookieTools.setCookie("usermessage",JSON.stringify(objUser),7)


				}
				layer.confirm("登录成功", {
						icon: 1,
						title:"登录提示",
						btn: ["立即去主页", "暂不"]
					}, function () {
						location = "./aaa.html";
					},
					function () {
						return
					})
			}



		})
		return false;
	})
})

//手机号验证登录
	$(function () {
		$(".loadbyphone").on("submit",function () {
			if($("[name='uphone']").val()==""){
				layer.msg("请输入手机号哟")
				return false
			}
			var flag=$("[name='upwd1']").val()==$(".loadbyphone>ul>li>a").text()
			if (!flag) {
				layer.msg("验证码有误哟")
				return  false;
			}
			let data={
				"uphone": $("[name='uphone']").val()
			}

			$.ajax({
				url:"./../server/loginByphone.php",
				data:data,
				dataType:"json",
				type:"post"
			}).then(function (res) {
				console.log(res)
				// location = "./index.html";
				if(res.status!=1){
					layer.msg("手机号有误哟")
				}
				if(res.status==1){
					layer.confirm("登录成功", {
						icon: 1,
						title:"登录提示",
						btn: ["立即去主页", "暂不"]
					}, function () {
						location = "./aaa.html";
					},
					function () {
						return
					})
					localStorage.setItem("user",JSON.stringify(res.data));
				}

			})
			return false;
		})
	})

//账号登录与手机号登录切换
	$(function () {
		$(".top>ul>li").on("click",function(){
			$(this).addClass("current").siblings().removeClass("current")
			if($(this).find("a").text()=="手机登录"){
				$(".loadbyphone").show()
				$(".loadbyname").hide()
			}
			if($(this).find("a").text()=="账号登录"){
				$(".loadbyphone").hide()
				$(".loadbyname").show()
			}
		})

//生成手机号登录验证码
		function randCode(){
			var str=""
			for(var i=0;i<4;i++){
				str+=parseInt(Math.random()*10)
			}
			return str
		}
		$(".loadbyphone li>a").on("click",function(){
			$(this).text(randCode())
		})
	})



//账号登录 注册链接跳转
$(function () {
$(".zhuce>a").on("click",function () {
	location.href="./register.html"
})

})